﻿shared float4x4 MatView;
shared float4x4 MatViewProj;

shared float3 SamplePos;
shared float3 SampleNorm;
shared float3 SampleTan;
shared float3 SampleBin;

float LightPointSize;
float3 LightValue;
float3 LightAtten;

float4 vsh(
	float3 iPos : POSITION,

	out float3 oPos : TEXCOORD0,
	out float oSize : PSIZE
) : POSITION
{
	oPos = iPos;
	oSize = LightPointSize;
	
	return mul( float4( iPos, 1 ), MatViewProj );
}

float4 psh_point( float3 iPos : TEXCOORD0 ) : COLOR
{
	float3 lVec = iPos - SamplePos;
	float dist = length( lVec );

	float atten_num = dot( normalize( lVec ), SampleNorm );
	float atten_denom = dot( LightAtten, float3( 1, dist, dist * dist ) );

	float3 cl = LightValue * max( atten_num / atten_denom, 0 );

	return float4( cl, 1 );
}

technique PointLight
{
	pass p0
	{
		VertexShader = compile vs_2_0 vsh();
		PixelShader = compile ps_2_0 psh_point();
	}
}